package com.m1book.domain.user;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import com.m1book.domain.book.ABook;

@Document(collection = "miser")
public class Miser implements Serializable {
	private static final long serialVersionUID = -2378214492053693678L;
	
	@Id
	private ObjectId id;
	
	@Indexed(unique = true)
	private String account;
	private String password;

	@Field(value = "info")
	private MiserInfo info;
	
	@Field(value = "role")
	private MiserRole role;
	
	@Field(value = "qq")
	private MiserQQAccount qqAccount;
	
	@Field(value = "sina")
	private MiserSinaAccount sinaAccount;
	
	@DBRef(collection = "abook")
	private List<ABook> donatABooks;
	
	private List<ObjectId> donatBooksId;
	
	@DBRef(collection = "abook")
	private List<ABook> holdABooks;
	
	private List<ObjectId> holdBooksId;
	
	public Miser() {
		id = ObjectId.get();
		role = new MiserRole(MiserRole.MEMBER);
		donatABooks = new LinkedList<ABook>();
		holdABooks = new LinkedList<ABook>();
		donatBooksId = new LinkedList<ObjectId>();
		holdBooksId = new LinkedList<ObjectId>();
	}

	public ObjectId getId() {
		return id;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public MiserInfo getInfo() {
		return info;
	}

	public void setInfo(MiserInfo info) {
		this.info = info;
	}

	public MiserRole getRole() {
		return role;
	}

	public void setRole(MiserRole role) {
		this.role = role;
	}

	public MiserQQAccount getQqAccount() {
		return qqAccount;
	}

	public void setQqAccount(MiserQQAccount qqAccount) {
		this.qqAccount = qqAccount;
	}

	public MiserSinaAccount getSinaAccount() {
		return sinaAccount;
	}

	public void setSinaAccount(MiserSinaAccount sinaAccount) {
		this.sinaAccount = sinaAccount;
	}

	public List<ABook> getDonatABooks() {
		return donatABooks;
	}

	public void setDonatABooks(List<ABook> donatABooks) {
		this.donatABooks = donatABooks;
	}

	public List<ABook> getHoldABooks() {
		return holdABooks;
	}

	public void setHoldABooks(List<ABook> holdABooks) {
		this.holdABooks = holdABooks;
	}

	public List<ObjectId> getDonatBooksId() {
		return donatBooksId;
	}

	public void setDonatBooksId(List<ObjectId> donatBooksId) {
		this.donatBooksId = donatBooksId;
	}

	public List<ObjectId> getHoldBooksId() {
		return holdBooksId;
	}

	public void setHoldBooksId(List<ObjectId> holdBooksId) {
		this.holdBooksId = holdBooksId;
	}

	@Override
	public String toString() {
		return "Miser [id=" + id + ", account=" + account + "]";
	}
}
